package huoye.shops.utils;

import android.content.Context;
import android.util.Log;

import com.codeideology.android.utils.DateUtils;
import com.codeideology.android.widget.pickerview.TimePickerView;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by user on 2017/11/27.
 */

public class PickerViewUtils {

    public static TimePickerView showYearMonthDay(Context context, Date date, TimePickerView.OnTimeSelectListener onListener) {
        Calendar endDate = Calendar.getInstance();
        endDate.setTime(new Date());

        Calendar startDate = Calendar.getInstance();
        startDate.clear();
        startDate.setTime(DateUtils.addYears(endDate.getTime(), - 100));
        startDate.set(Calendar.MONTH, 0);// 注意,Calendar对象默认一月为0


        Log.e("ccccc",startDate+"+"+endDate);

        TimePickerView pvTime = new TimePickerView.Builder(context, onListener)
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel( null, null, null, null, null, null)
                .isCenterLabel(false)
                .setTitleText("选择时间")
                .setDecorView(null)
                .isDialog(false)
                .setRangDate(startDate,endDate)
                .build();
        Calendar calendar = DateUtils.getCalendar();
        calendar.setTime(date);
        pvTime.setDate(calendar);
        return pvTime;
    }



    //特权选择
    public static TimePickerView showEventYearMonthDay(Context context, Date date, TimePickerView.OnTimeSelectListener onListener) {
        Calendar startDate = Calendar.getInstance();
        startDate.setTime(new Date());

        Calendar endDate = Calendar.getInstance();
        endDate.clear();
        endDate.setTime(DateUtils.addYears(startDate.getTime(), + 10));
        endDate.set(Calendar.MONTH, 0);// 注意,Calendar对象默认一月为0*/

        TimePickerView pvTime = new TimePickerView.Builder(context, onListener)
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel( null, null, null, null, null, null)
                .isCenterLabel(false)
                .setTitleText("选择时间")
                .setDecorView(null)
                .isDialog(false)
                .setRangDate(startDate,endDate)
                .build();
        Calendar calendar = DateUtils.getCalendar();
        calendar.setTime(date);
        pvTime.setDate(calendar);
        return pvTime;
    }

    //活动选择
    public static TimePickerView showEventYearMonthDayHourMinute(Context context, Date date, TimePickerView.OnTimeSelectListener onListener) {
        Calendar startDate = Calendar.getInstance();
        startDate.setTime(new Date());

        Calendar endDate = Calendar.getInstance();
        endDate.clear();
        endDate.setTime(DateUtils.addYears(startDate.getTime(), + 10));
        endDate.set(Calendar.MONTH, 0);// 注意,Calendar对象默认一月为0*/

        TimePickerView pvTime = new TimePickerView.Builder(context, onListener)
                .setType(new boolean[]{true, true, true, true, true, false})
                .setLabel( null, null, null, null, null, null)
                .isCenterLabel(false)
                .setTitleText("选择时间")
                .setDecorView(null)
                .isDialog(false)
                .setRangDate(startDate,endDate)
                .build();
        Calendar calendar = DateUtils.getCalendar();
        calendar.setTime(date);
        pvTime.setDate(calendar);
        return pvTime;
    }




    public static TimePickerView showYearMonth(Context context, Date date, TimePickerView.OnTimeSelectListener onListener) {
        Calendar endDate = Calendar.getInstance();
        endDate.setTime(date);

        Calendar startDate = Calendar.getInstance();
        startDate.clear();
        startDate.setTime(DateUtils.addYears(endDate.getTime(), - 100));
        startDate.set(Calendar.MONTH, 0);// 注意,Calendar对象默认一月为0


        TimePickerView pvTime = new TimePickerView.Builder(context, onListener)
                .setType(new boolean[]{true, true, false, false, false, false})
                .setLabel( null, null, null, null, null, null)
                .isCenterLabel(false)
                .setTitleText("选择时间")
                .setDecorView(null)
                .isDialog(false)
                .setRangDate(startDate,endDate)
                .build();
        Calendar calendar = DateUtils.getCalendar();
        calendar.setTime(date);
        pvTime.setDate(calendar);
        return pvTime;
    }

}
